const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');
const Novel = require('./Novel');
const Reader = require('./Reader');

const Comment = sequelize.define('Comment', {
  comment_id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  novel_id: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  reader_id: {
    type: DataTypes.STRING,
    allowNull: false
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: false
  },
  likes: {
    type: DataTypes.INTEGER,
    defaultValue: 0
  }
}, {
  tableName: 'comment',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at'
});

Comment.belongsTo(Novel, { foreignKey: 'novel_id', as: 'novel' });
Comment.belongsTo(Reader, { foreignKey: 'reader_id', as: 'reader' });

module.exports = Comment;